package net.zjitc.controller.client;

import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Author admin
 * @Date 2019/5/22 10:18
 */
@Controller
public class LoginController {
    @Autowired
    UserService userService;

    @RequestMapping(value = "/loginUI")
    public String loginUI(){
        return "/client/login";
    }

    @RequestMapping(value = "/login")
    public String login(User user, Model model, HttpSession session){
        User u = userService.user_login(user.getTelephone(),user.getPassword());
        if (u != null)
        {
            session.setAttribute("user",u);
            return "redirect:/index";
        }
        model.addAttribute("news","账号或密码错误，请重新输入");
        return "/client/login";
    }

    @RequestMapping(value = "/logout")
    public String logout(HttpSession session){
        session.removeAttribute("user");
        return "redirect:/index";
    }
}
